<!DOCTYPE html>
<html>
<head>
    <meta charset='utf-8'>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <link rel="shortcut icon" type="image/x-icon" href="../favicon.ico"/>
    <title>让自动扫描发现用户自定义的扩展方法/函数/标签 Class jetbrick-template</title>

    <link href="../assets/css/application.min.css" rel="stylesheet" type="text/css"/>

    <!--[if lt IE 9]><script src="../assets/js/html5shiv.js"></script><![endif]-->
    <script type="text/javascript" src="../assets/js/application.min.js"></script>
</head>

<body>
<a href="https://github.com/subchen/jetbrick-template/" target="_blank">
    <img src="../assets/images/forkme_right_orange.png" alt="Fork me on GitHub" class="fork-me-on-github">
</a>

<div class="jb-topbar">
    <div class="container">
        <a href="http://subchen.github.io/"><img src="../assets/images/logo-mini.png"/></a>
        <!--
        <ul class="menubar">
            <li><a href="">commons</a></li>
            <li><a href="">webmvc</a></li>
            <li><a href="">template</a></li>
            <li><a href="">orm</a></li>
            <li><a href="">widget</a></li>
            <li><a href="">javadoc-chm</a></li>
        </ul>
        -->
        <div class="pull-right" style="color:#fff;line-height:40px;font-size:16px;padding-right:20px">QQ 交流圈：310491655</div>
    </div>
</div>

<div class="jb-banner">
    <div class="container">
        <a href="http://subchen.github.io/jetbrick-template/index.html">
            <img src="../assets/images/jetbrick-template-logo.png" class="pull-left" />
        </a>
        <ul class="description">
            <li>1. 全新一代 Java 模板引擎</li>
            <li>2. 具有高性能、高扩展性</li>
            <li>3. 完美替代 JSP, Velocity 等引擎模板</li>
        </ul>
        <a href="download/jetbrick-template-1.2.3.zip" class="download-button">
            <img src="../assets/images/download.png"/>
            <span>jetbrick-template-1.2.3.zip<br/>2014-03-10</span>
        </a>
    </div>
</div>

<div class="container">
    <div class="jb-section">
        <ul class="tabs">
            <li><a href="overview.html">简介</a></li>
            <li><a href="download.html">下载</a></li>
            <li><a href="userguide.html">开发指南</a></li>
            <li><a href="config.html">配置指南</a></li>
            <li><a href="syntax.html">语法指南</a></li>
            <li><a href="integrate.html">Web 框架集成</a></li>
            <!--
            <li><a href="example.html">例子</a></li>
            -->
            <li><a href="faq.html" class="selected">FAQ</a></li>
            <li><a href="about.html">关于</a></li>
        </ul>
    </div>
</div>

<div class="container">
    <div class="announcement">
        <a href="download.html#version">2014-03-10：jetbrick-template-1.2.3 正式版已发布，欢迎下载。</a>
    </div>
</div>

<div class="container">


    <div class="markdown">

<!-- markdown body begin -->
	<ul> 
 <li><a href="faq-compile.html">jetbrick-template 将模板编译成 Java Class 有什么好处？</a></li> 
 <li><a href="faq-define.html">jetbrick-template 中为什么需要 #define 声明变量类型？</a></li> 
 <li><a href="faq-error.html">jetbrick-template 常见错误分析</a></li> 
 <li><a href="faq-autoscan.html">jetbrick-template 如何让自动扫描发现用户自定义的扩展方法/函数/标签 Class</a></li> 
 <li><a href="faq-include.html">jetbrick-template 中如何嵌入子模板？（父子间参数传递）</a></li> 
 <li><a href="faq-tag.html">jetbrick-template 中如何自定义 Tag？</a></li> 
 <li><a href="faq-layout.html">jetbrick-template 中如何实现 layout 功能？</a></li> 
 <li><a href="faq-spring.html">jetbrick-template 在 Spring 中的集成方法</a></li> 
</ul>

    <h1><a name="x40853102"></a><span>1 如何自动发现用户自定义的扩展方法/函数/标签 Class</span></h1>
<p>jetbrick-template 主要的扩展点有下列几个：</p> 
<ol> 
 <li>扩展方法</li> 
 <li>扩展函数</li> 
 <li>自定义标签 #tag</li> 
</ol>
<p>常规的配置方法如下：</p> 
<script type="syntaxhighlighter" class="brush: text"><![CDATA[
# 扩展方法
import.methods = app.methods.StringMethods, app.methods.DateMethods

# 扩展函数
import.functions = app.functions.UserFunctions

# 自定义标签
import.tags = app.tags.UserTags, app.tags.CacheTags
]]></script>
<p>如果需要增加或者调整 Class，需要同时维护这个配置文件，比较麻烦。</p>
<p>从 1.1.2 开始，增加 annotation 自动扫描查找 Methods / Functions / Tags Class 的功能</p>
<p>具体的 annotation 如下：</p> 
<script type="syntaxhighlighter" class="brush: java"><![CDATA[
@JetAnnotations.Methods
@JetAnnotations.Functions
@JetAnnotations.Tags
]]></script>
<p>只要在对应的 Class 中，增加对应的 annotation 即可。</p>
<p>例如：</p> 
<script type="syntaxhighlighter" class="brush: java"><![CDATA[

@JetAnnotations.Methods
public class StringMethods {
    ...
}
]]></script>
<p>然后开启 <code>import.autoscan = true</code> 就可以自动发现了。</p>
<p>当然，为了加快发现的速度，建议同时配置 <code>import.autoscan.packages</code>。</p>
<p>Good luck.</p>

<!-- markdown body end -->

    </div>
</div>

<div class="container">
    <div class="jb-footer">
        Copyright 2010-2014 Guoqiang Chen. All rights reserved.
        <br/>subchen&#64;gmail.com, QQ 交流圈：310491655
    </div>
</div>

<style type="text/css">
#cnzz_stat_icon_1000210720 {
	display: none;
}
</style>
<script type="text/javascript">
var cnzz_protocol = (("https:" == document.location.protocol) ? " https://" : " http://");
document.write(unescape("%3Cspan id='cnzz_stat_icon_1000210720'%3E%3C/span%3E%3Cscript src='" + cnzz_protocol + "s22.cnzz.com/z_stat.php%3Fid%3D1000210720' type='text/javascript'%3E%3C/script%3E"));
</script>



</body>
</html>
